﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 植物的基类
/// </summary>
public abstract class PlantBase : MonoBehaviour
{
    protected Animator animator;
    protected SpriteRenderer spriteRenderer;
    protected Grid currGrid;

    protected void Find()
    {
        animator = GetComponent<Animator>();
        spriteRenderer = GetComponent<SpriteRenderer>();
    }
    //创建时初始化
    public void InitForCreate(bool inGrid)
    {
        Find();
        animator.speed = 0;
        if (inGrid)
        {
            spriteRenderer.sortingOrder = -1;
            spriteRenderer.color = new Color(1, 1, 1, 0.6f);
        }
        else
        {
            spriteRenderer.sortingOrder = 1;
        }

    }
    //放置时初始化
    public void InitForPlace(Grid grid)
    {
        currGrid = grid;
        currGrid.CurrPlantBase = this;
        transform.position = grid.position;
        animator.speed = 1;
        spriteRenderer.sortingOrder = 0;
        OnInitForPlace();
    }

    protected virtual void OnInitForPlace()
    {

    }
}
